home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8231 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: stc06.ctd.ornl.gov!msr!kennel
  2. From: kennel@msr.epm.ornl.gov (Matt Kennel)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: Performance: C vs. C++
  5. Date: 15 Feb 1996 22:36:13 GMT
  6. Organization: Oak Ridge National Lab, Oak Ridge, TN
  7. Message-ID: <4g0cgt$a3l@stc06.ctd.ornl.gov>
  8. References: <30F6BAAC.12B5@iastate.edu> <4da9pn$a45@news.bridge.net> <AUSTERN.96Feb15134314@isolde.mti.sgi.com>
  9. NNTP-Posting-Host: msr.epm.ornl.gov
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Matt Austern (austern@isolde.mti.sgi.com) wrote:
  13. > In article <4fvr7k$a3l@stc06.ctd.ornl.gov> kennel@msr.epm.ornl.gov (Matt Kennel) writes:
  14.  
  15. > > > What is a "dispatched pointer"?
  16. > > 
  17. > > In C++ it would be a pointer to a base class which has 'virtual members',
  18. > > where the particular function called is chosen by the actual run-time 
  19. > > type. 
  20. > > 
  21. > > In C++, if you have a pointer, then it is always conceivably dispatched,
  22. > > unless everything in the class is declared "static".   
  23. > > 
  24. > > So here "reference semantics" (going through a pointer, a storage area 
  25. > > potentially aliased) are joined with "dispatchability".
  26.  
  27. > That's not quite true.  In C++, a function call is dispatched only if
  28. > the function is declared as virtual in the base class.  You don't have
  29. > to make any special declaration of a function to make it
  30. > non-dispatched; you simply have to avoid doing anything special.
  31. > Declaring a function to be static is something else entirely.
  32.  
  33. Sorry.  I apologize for the mistake.
  34.  
  35. I still think it's awkward that the maker of the class needs to 
  36. determine what is dispatched and what is not; I prefer the user 
  37. getting the choice. 
  38.  
  39. > And if you do have a pointer to a polymorphic class, and you want to
  40. > call a virtual function and ensure that you're calling the base 
  41. > class's version, that's actually possible: instead of writing
  42. > base_pointer->f(), you write base_pointer->base::f().  The syntax
  43. > is ugly, to be sure, but it doesn't bother me that you have to use
  44. > ugly syntax for such a rare operation.
  45.  
  46. Does it work with []??
  47.  
  48. I.e.
  49.  
  50.     MyMatrix x;
  51.  
  52.     x[3][2] = 4; 
  53.  
  54. That was a problem we sometimes ran into in C++ vs. Sather.  We found
  55. that in compiling Sather it is crucial that any array operations
  56. not ever be dispatched inside loops so that they could be inlined.  Only
  57. then could strength reductions be applied, and then only if the array pointer
  58. could be proven to be a loop constant. 
  59.  
  60. Typically available C++ matrix classes were not able to do this on
  61. the compilers we had. 
  62.  
  63.  
  64.  
  65. > -- 
  66. > Matt Austern
  67. > SGI: MTI Compilers Group
  68. > austern@isolde.mti.sgi.com
  69.